layui.use(['transfer', 'layer', 'util'], function() {
    var $ = layui.$
        , transfer = layui.transfer
        , layer = layui.layer
        , util = layui.util;

    //查询一位用户的权限
    let id=localStorage.getItem("roleJurisdictionUpdateById");
    let code=localStorage.getItem("roleJurisdictionUpdateBycode");
    $("#roleByName").text(code);
    let da=myAjaxGet("/role/roleJurisdictionFindById",{id:id},"get");
    // console.log(da)
    da=da.data;
    let data2='';
    for (let i=0; i<da.length;i++){
        data2 +='"'+da[i].jurisdictionCode+'",'
    }
    data2= '['+data2+']';
    data2 = eval('(' + data2 + ')');
    console.log(data2)
    // console.log(data2)


    //查询用户所有权限
    // let code=myAjax("/user/findById",{id:id},"post");
    // code=code.userbean.code;
    let data=myAjaxGet("/role/roleJurisdictionFindAll","","get");
    data=data.data;
    // console.log(data)
    let data1='';
    for (let i=0; i<data.length;i++){
        data1 +='{"value": "'+data[i].jurisdictionCode+'", "title": "'+data[i].jurisdictionName+'", "code": "'+code+'"},'
    }
    data1= '['+data1+']';
    data1 = eval('(' + data1 + ')');
    // console.log(data1)


    //穿梭时的回调
    transfer.render({
        elem: '#test1'
        , title: ['角色未拥有权限', '角色已拥有权限']
        , data: data1
        , value:data2
        ,showSearch: true
        ,height: 450 //定义高度
        , onchange: function (obj, index) {
            var arr = ['1', '2'];
            // layer.alert('来自 <strong>'+ arr[index] + '</strong> 的数据：'+ JSON.stringify(obj)); //获得被穿梭时的数据
            if (arr[index] == 1) {
                let data = myAjax("/role/roleJurisdictionAdd", obj, "post");
                // console.log(data);
                data = data.code;
                if (data == 200) {
                    layer.alert('成功添加权限');
                } else {
                    layer.alert('添加权限失败');
                }
            } else if (arr[index] == 2) {
                let data = myAjax("/role/roleJurisdictionFrozen", obj, "post");
                data = data.code;
                if (data == 200) {
                    layer.alert('成功移除权限');
                } else {
                    layer.alert('移除权限失败');
                }
            }
        }
    })
});






